package com.jingding.procurement.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jingding.procurement.mapper.MaterialEnquiryMapper;
import com.jingding.procurement.pojo.vo.MaterialClassVO;
import com.jingding.procurement.pojo.vo.MaterialVO;
import com.jingding.procurement.service.MaterialEnquiryService;
import com.jingding.procurement.web.PageResult;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialEnquiryServiceImpl implements MaterialEnquiryService {

    @Autowired
    private MaterialEnquiryMapper materialEnquiryMapper;



    @Override
    public PageResult selMaterial(String invcode/*物料编码*/,String invname/*物料名称*/,String invstd/*型号规格*/,String invccode/*物料分类编码*/,String invcname/*物料分类名称*/,
                                  Integer page,Integer rows) {
        if (rows!=null||page!=null){
            PageHelper.startPage(page,rows);
        }else {
            PageHelper.startPage(1,20);
        }

        List<MaterialVO> materialVO = materialEnquiryMapper.selMaterial(invcode,invname,invstd,invccode,invcname);
        PageInfo<MaterialVO> info = new PageInfo<>(materialVO);
        PageResult pageResult = new PageResult(materialVO,info.getPageSize(),info.getPageNum(),
                info.getTotal(),info.getPages(), info.isHasPreviousPage(), info.isHasNextPage());
        return pageResult;
    }

    @Override
    public List<MaterialClassVO> selMaterialClass() {
        List<MaterialClassVO> materialClassVO = materialEnquiryMapper.selMaterialClass();
        return materialClassVO;
    }
}
